﻿using Fozzy;
using Fozzy.Family;
using Fozzy.Gedcom;

namespace Microsoft.FamilyShow
{
    public class People2                                                    : Persons
    {
        #region States
            internal bool                       Be_Old                      { get { return Name.Be_Empty || new File2(Name).Be_Old  ; } }
            internal bool                       Be_New                      { get { return ! Be_Old                                 ; } }
        #endregion

        #region Structure
        #endregion

        #region Properties
            private Dialog              Dialog                              { get { return new SaveAs(Directory)                    ; } }
        #endregion

        #region Constructeur
            //new RoutedEventHandler(OpenRecentFile_Click)
            public People2(string filename)                                  : base(new Fozzy.File(filename))
            {}
            public People2(Fozzy.File file)                                  : base(file)
            {}
        #endregion

            protected override void Prepare()
            {
                base.Prepare()                                              ;
                Recentise()                                                 ;
            }

            /// <summary>
            /// Prompt to save if the file has not been saved before, 
            /// otherwise just save to the existing file.
            /// </summary>
            public override void Save()
            {
                if (Be_Old)
                {
                    if (Dialog.Be_Complete)
                    {
                        Save(Dialog.Selection)                              ;
                        Recentise()                                         ;
                    }
                }
                else base.Save()                                            ;
            }

            private void Recentise()
            {
                Module.Recents.Add(File)                                    ;
            }
            
            // Load the selected family file based on the file extension
            //if (fileName.EndsWith(Properties.Resources.DefaultFamilyExtension))
            //    familyCollection.LoadOPC();
            //else
            //{
            //    family.IsOldVersion = true;
            //    familyCollection.LoadVersion2();
            //}

            /// <summary>
            /// Export était déjà utilisé ... C'est chiant
            /// </summary>
            public void Extract()
            {
                Extract(Name)                                               ;
            }

            public void Extract(string fullname)
            {
                new Writer(fullname, Instances)                             ;
            }

        //using (writer = new StreamWriter(gedcomFilePath))
        //{
        //    WriteLine(0, "HEAD", "");
        //    ExportPeople();
        //    ExportFamilies();
        //    WriteLine(0, "TRLR", "");
        //}

    }
}
